import store from "@/store";
import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";
import HomeView from "../views/HomeView.vue";

const routes: Array<RouteRecordRaw> = [
  {
    path: "/",
    name: "home",
    meta:{sign:true},
    component: HomeView,
    children:[
      // 系统管理
      {path:'user',component:()=>import('../views/system/UserView.vue')},
      {path:'group',component:()=>import('../views/system/GroupView.vue')},
      {path:'jurisdiction',component:()=>import('../views/system/JurisdictionView.vue')},
      {path:'customer',component:()=>import('../views/system/CustomerView.vue')},
      {path:'parameter',component:()=>import('../views/system/ParameterView.vue')},
      {path:'data',component:()=>import('../views/system/DataView.vue')},

      // 入库管理
      {path:'ware-handing',component:()=>import('../views/admin/Ware_handing.vue')},
      {path:'inspec',component:()=>import('../views/admin/InspecView.vue')},
      {path:'ins',component:()=>import('../views/admin/InspectionView.vue')},
      {path:'recquary',component:()=>import('../views/admin/RecQuary.vue')},
      // 出库管理
      {path:'outstockg',component:()=>import('../views/outstock/OutStockView.vue')},
      {path:'outtrue',component:()=>import('../views/outstock/OutTrueView.vue')},
      {path:'outtrue2',component:()=>import('../views/outstock/OutTrue2View.vue')},
      {path:'outtrue3',component:()=>import('../views/outstock/OutTrue3View.vue')},
      // 过户管理
      {path:'management',component:()=>import('../views/transfer/ManagementView.vue')},
      {path:'transact',component:()=>import('../views/transfer/TransactView.vue')},
      // 调仓管理
      {path:'deploy',component:()=>import('../views/deploy/DeployView.vue')},
      {path:'syym',component:()=>import('../views/deploy/SyymView.vue')},
      // 盘点管理
      {path:'guan',component:()=>import('../views/Inventory/GuanView.vue')},
      {path:'search',component:()=>import('../views/Inventory/SearchView.vue')},
      // 资产管理
      {path:'warehouse',component:()=>import('../views/management/WareHouseView.vue')},
      {path:'position',component:()=>import('../views/management/PositionView.vue')},
      {path:'tray',component:()=>import('../views/management/TrayView.vue')},
      // 业务查询
      {path:'details',component:()=>import('../views/business/DetailsView.vue')},
      {path:'lnventory',component:()=>import('../views/business/LnventoryView.vue')},
      {path:'utilization',component:()=>import('../views/business/UtilizationView.vue')},
      // {path:'listorder',component:()=>import('../views/order/ListOrder.vue')},
      // dash页面为子路由的默认页面
      // {path:'',redirect:'/admin/dash'},
      {path:':noMatch(.*)',component:()=>import('../views/NoMatch.vue')},

    ]
  },

  {
    path: "/login",
    name: "login",
    component: () => import('../views/LoginView.vue'),
  },
  {
    path: "/about",
    name: "about",
    meta:{sign:true},
    component: () =>import(/* webpackChunkName: "about" */ "../views/AboutView.vue"),
  },
  {
    path: '/outstock',
    name: 'outstock',
    component: ()=>import('../views/outstock/OutStockView.vue'),
   
  },
  {
    path: '/management',
    name: 'management',
    component: () => import('../views/transfer/ManagementView.vue')
  },

  {
    path: '/about',
    name: 'about',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  }
]
const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

router.beforeEach((to,from,next)=>{
	if(to.meta.sign){
		if(sessionStorage.getItem("isLog")){
			// 如果本地存储有isLog(即已经登录)可以进
      store.dispatch("userInfoAction")
			next(true);
		}else{
			next("/login?redirect="+to.path)
		}
	}else{
		next(true);
	}
})

export default router;
